package cn.tedu.hotel.controller;

import cn.tedu.hotel.pojo.dto.FacilitiesAddNewDTO;
import cn.tedu.hotel.pojo.vo.FacilitiesListItemVO;
import cn.tedu.hotel.service.IFacilitiesService;
import cn.tedu.hotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

/**
 *  房间设施数据相关的控制器类
 */
@Api(tags = "09. 房间设施管理模块")
@Slf4j
@RestController
@RequestMapping("/facilities")
public class FacilitiesController {

    @Autowired
    IFacilitiesService facilitiesService;

    public FacilitiesController(){
        log.debug("创建控制器：FacilitiesController");
    }

    @ApiOperation("添加房间设施")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(FacilitiesAddNewDTO facilitiesAddNewDTO){
        log.debug("开始处理【添加房间设施】的请求，参数：{}",facilitiesAddNewDTO);
        facilitiesService.addNew(facilitiesAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除房间设施")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理【删除房间设施】的请求：id={}",id);
        facilitiesService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询房间设施列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("")
    public JsonResult<List<FacilitiesListItemVO>> listFacilities(){
        log.debug("开始处理【查询房间设施列表】的请求");
        List<FacilitiesListItemVO> facilitiesListItemVOS = facilitiesService.listFacilities();
        return JsonResult.ok(facilitiesListItemVOS);
    }
}
